package com.company.finance.ddd.domain.core.voucher.rule.concrete;

import com.company.finance.ddd.common.FlagEnum;
import com.company.finance.ddd.domain.core.voucher.enums.VoucherSubjectEnum;
import com.company.finance.ddd.domain.core.voucher.rule.*;
import com.company.finance.ddd.domain.core.bill.enums.BillSubTypeEnum;
import com.company.finance.ddd.domain.core.voucher.rule.VoucherType;
import org.springframework.stereotype.Component;

/**
 *
 * @author wanglei
 * @version $$Id: PaymentRule, v 0.1 2021/2/3 14:56 wanglei Exp $$
 */
@Component
public class PaymentRuleHolder extends RuleHolder {

    @Override
    protected RuleDefinition createRuleDefinition() {
        return RuleDefinition.builder().voucherType(VoucherType.builder().code("04").name("付款").build())
                .addBillSpecification(buildBillSpecificationForPurchasePayment())
                .addBillSpecification(buildBillSpecificationForRelatedTransaction())
                .build();
    }

    private RuleDefinition.BillSpecification buildBillSpecificationForRelatedTransaction() {
        return RuleDefinition.BillSpecification.builder()
                .prepayment(FlagEnum.NO).relateDeal(FlagEnum.NO)
                .billSubTypeEnum(BillSubTypeEnum.RELATED_TRANSACTION)
                .billItemRule(BillItemRule.builder()
                        .creditSubject(VoucherSubjectEnum.BANK)
                        .creditDigestRule(BillItemRule.DigestRule.builder()
                                .layout("companyName支付supplierName关联交易")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .debitSubject(VoucherSubjectEnum.SHOULD_RECEIPT_SETTLE)
                        .debitDigestRule(BillItemRule.DigestRule.builder()
                                .layout("supplierName收到companyName关联交易")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .build())
                .build();
    }

    private RuleDefinition.BillSpecification buildBillSpecificationForPurchasePayment() {
        return RuleDefinition.BillSpecification.builder()
                .prepayment(FlagEnum.NO).relateDeal(FlagEnum.NO)
                .billSubTypeEnum(BillSubTypeEnum.PURCHASE_PAYMENT)
                .billItemRule(BillItemRule.builder()
                        .creditSubject(VoucherSubjectEnum.FIXED_ASSETS)
                        .creditDigestRule(BillItemRule.DigestRule.builder()
                                .layout("companyName支付supplierName")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .debitSubject(VoucherSubjectEnum.SHOULD_RECEIPT_SETTLE)
                        .debitDigestRule(BillItemRule.DigestRule.builder()
                                .layout("supplierName收到companyName")
                                .placeholder(new String[]{"companyName", "supplierName"})
                                .layoutSetter(new VoucherDigestSetter())
                                .build())
                        .build())
                .build();
    }
}
